package com.neuedu.common;

import lombok.Data;

/**
 * @Author hj
 * @Date 2023/11/28 14:39
 * @PackageName:com.hnu.dto
 * @ClassName: R
 * @Description: create a class
 * @Version 1.0
 */
@Data
public class R {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息内容
     */
    private String msg;
    /**
     * 是否成功
     */
    private Boolean success;
    /**
     * 需要传递的数据
     */
    private Object data;

    /**
     * 总记录
     */
    private Long totalNum;

    /**
     * 操作成功
     * @return
     */
    public static R ok(){
        R r = new R();
        r.setSuccess(true);
        r.setCode(200);
        r.setMsg("操作成功");
        return r;
    }
    /**
     * 操作失败
     * @return
     */
    public static R error(){
        R r = new R();
        r.setSuccess(false);
        r.setCode(500);
        return r;
    }

    /**链式编程方法*/
    public R msg(String msg){
        this.setMsg(msg);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R data(Object data){
        this.setData(data);
        return this;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public R totalNum(Long totalNum){
        this.setTotalNum(totalNum);
        return this;
    }
}
